<?php
session_start();
include_once $_SERVER['DOCUMENT_ROOT']."/math-videos/configure.inc.php";
//check if you have curl loaded
//echo $_REQUEST['json'];
$data_string = json_decode($_REQUEST['json']);   
foreach($data_string as $key=>$value)
{
	$$key = trim($value);
    //   echo "$key=$value".'<br>';
}  
//exit;
//check asset table 
$id= $assetID;
$sqltext="select title, abstract, lecture_date, duration, asset_type, abstract_url, remote_url, location, event_title, created_datetime, created_by, last_modified_datetime, last_modified_by, rating, views, thumbnail from asset WHERE id=?";
$params = array();

array_push($params,sql_escape($id));
$result = db_select_query($conn,$sqltext,$params);
/*$has_assetid = false;
while($row = db_fetch_array($result))
{
	$has_assetid = true;
}*/
if(db_num_rows($result)<1)
{
	echo "Error 404 AssetId Not Found!";
}
else
{
	unset($result_array);
	unset($presenter_array);
	while($row = db_fetch_object($result))
	{
		foreach ($row as $key => $value) 
		{
			$value = trim($value);
			//$$key = $value;
			$result_array[$key]=$value;
		}
	}
//get presenter
	$sqltext="SELECT first_name, last_name, middle_name, alt_name, suffix, title, department, organization FROM presenter  WHERE asset_id= ?";
	$params = array();
	array_push($params,sql_escape($id));
	$result = db_select_query($conn,$sqltext,$params);
	while($row = db_fetch_object($result))
	{
		foreach ($row as $key => $value) 
		{
			$value = trim($value);
			//$$key = $value;
			//$presenter_array[$key]=$value;
			$result_array["presenter"][$key]=$value;
		}
	}

		//get keywords
		
	$sqltext="SELECT keyword FROM keyword  WHERE asset_id= ?";
	$params = array();
	array_push($params,sql_escape($id));
	$result = db_select_query($conn,$sqltext,$params);
	while($row = db_fetch_object($result))
	{
		foreach ($row as $key => $value) 
		{
			$value = trim($value);
			//$$key = $value;
			$result_array[$key]=$value;
		}
	}
		//get timecode
	$sqltext="SELECT timecode, timecode_type, data FROM timecode  WHERE asset_id= ?";
	$params = array();
	array_push($params,sql_escape($id));
	$result = db_select_query($conn,$sqltext,$params);
	while($row = db_fetch_object($result))
	{
		foreach ($row as $key => $value) 
		{
			$value = trim($value);
			//$$key = $value;
			$result_array[$key]=$value;
		}
	}
			//get msc_number
	$sqltext="SELECT msc FROM msc_number  WHERE asset_id= ?";
	$params = array();
	array_push($params,sql_escape($id));
	$result = db_select_query($conn,$sqltext,$params);
	while($row = db_fetch_object($result))
	{
		foreach ($row as $key => $value) 
		{
			$value = trim($value);
			//$$key = $value;
			$result_array[$key]=$value;
		}
	}
	
	//return json array
	/*$result_array = array("title" => "$title", 
			  "lecture_date"=> "$lecture_date",
			  "remote_url" => "$remote_url",
			  "organization" => "$organization",
				"presenter" => "$first_name $last_name",
				"job_title" => "$job_title",
				"keyword" => "$keyword",
				"timecode" => "$timecode",
				"timecode_type" => "$timecode_type",
				"data" =>"$data",
				"assetID" =>"$id"
			  ); */
	print_r($result_array);    
	}
?>